package com.wit.action;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class BackUpAction {
	private String username;
	private String password;
	private String database;
	private String baseIP;
	private String filePath;
	private String mysqlPath;
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getDatabase() {
		return database;
	}
	public void setDatabase(String database) {
		this.database = database;
	}
	public String getBaseIP() {
		return baseIP;
	}
	public void setBaseIP(String baseIP) {
		this.baseIP = baseIP;
	}
	public String getFilePath() {
		return filePath;
	}
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	public String getMysqlPath() {
		return mysqlPath;
	}
	public void setMysqlPath(String mysqlPath) {
		this.mysqlPath = mysqlPath;
	}
	
	 public String backup_run(){
		 String stmt=null;
		 stmt=mysqlPath+" "+database+" -h "+baseIP+" -u"+username+" -p"+password
                +" utf8"+" --result-file="+filePath;
	       System.out.println(stmt); 
	       try {
	    	   Process process = Runtime.getRuntime().exec(stmt);
	    	   InputStreamReader ir = new InputStreamReader(process
	    	     .getInputStream());
	    	   LineNumberReader input = new LineNumberReader(ir);
	    	   String line;
	    	   while ((line = input.readLine()) != null)
	    	    System.out.println(line);
	    	   input.close();
	    	   return "success";
	    	  } catch (IOException e) {
	    	   e.printStackTrace();
	    	   return "faile";
	    	  }


	    }
	 public String picPath(String path) {
			String[] newpath = path.split("\\");
			System.out.println(newpath.length);
			String pic = newpath[0] + "\\\\";
			for (int i = 1; i < newpath.length - 1; i++) {
				pic += newpath[i] + "\\\\";
			}
			pic += newpath[newpath.length - 1];
			System.out.println(pic);
			return pic;
		}

}
